package com.jeecg;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

//http://localhost/welcome.html
public class WebServer{
	public static void main(String[] args) {
		int port = 80;
		if (args.length == 1) {
			port = Integer.parseInt(args[0]);
		}
		new WebServer().serverStart(port);//启动web服务器
	}
	
	/**
	 * 服务器启动，建立ServerSocket，监听客户端的请求
	 * 当请求到来，建立socket连接，使用子线程处理socket连接
	 * @param port
	 */
	public void serverStart(int port) {
		try {
			ServerSocket serverSocket = new ServerSocket(port);
			while (true) {
				Socket socket = serverSocket.accept();
				new ServerSocketHandler(socket).start();//启动子线程处理客户端请求
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
